using System;
using System.Collections.Generic;
using System.Text;
using ClickSocial.Framework;
using ClickSocial.Data;
using ClickSocial.Entities;
using System.Collections;
using System.Web;

namespace ClickSocial.Components
{
    public class VentaItem
    {
        #region Singleton
        static VentaItemDal _instance;
        public VentaItem()
        {

        }
        public static VentaItemDal Instance()
        {
            if (_instance == null)
            {
                if (HttpContext.Current == null)
                    _instance = new VentaItemDal();
                else
                {
                    VentaItemDal inst = HttpContext.Current.Items["VentaItemDalSingleton"] as VentaItemDal;
                    if (inst == null)
                    {
                        inst = new VentaItemDal();
                        HttpContext.Current.Items.Add("VentaItemDalSingleton", inst);
                    }
                    return inst;
                }
            }
            return _instance;
        } 
        #endregion

        #region List
        static public List<VentaItemInfo> GetAllByEstadoCliente(string cliente, string estado)
        {
            List<VentaItemInfo> lst_venta_item_info = new List<VentaItemInfo>();

            try
            {
                lst_venta_item_info = CBO.FillCollection<VentaItemInfo>(Instance().GetAllByEstadoCliente(cliente, estado));
            }
            catch (Exception ex)
            {
                Hashtable addInfo = new Hashtable();
                addInfo.Add("cliente", cliente);
                throw ExceptionManager.Handle(ex, "Error al recuperar items de la venta", addInfo);
            }

            return lst_venta_item_info;
        }

        static public List<VentaItemInfo> GetAllByVentaID(long id)
        {
            List<VentaItemInfo> lst_venta_item_info = new List<VentaItemInfo>();

            try
            {
                lst_venta_item_info = CBO.FillCollection<VentaItemInfo>(Instance().GetAllByVentaID(id));
            }
            catch (Exception ex)
            {
                Hashtable addInfo = new Hashtable();
                addInfo.Add("id", id.ToString());
                throw ExceptionManager.Handle(ex, "Error al recuperar items de la venta", addInfo);
            }

            return lst_venta_item_info;
        }
        static public List<VentaItemInfo> GetAllByVentaIDFotografo(long id, string fotografo)
        {
            List<VentaItemInfo> lst_venta_item_info = new List<VentaItemInfo>();

            try
            {
                lst_venta_item_info = CBO.FillCollection<VentaItemInfo>(Instance().GetAllByVentaIDFotografo(id, fotografo));
            }
            catch (Exception ex)
            {
                Hashtable addInfo = new Hashtable();
                addInfo.Add("ventaId", id.ToString());
                addInfo.Add("fotografo", fotografo);
                throw ExceptionManager.Handle(ex, "Error al recuperar items de la venta por fotografo", addInfo);
            }

            return lst_venta_item_info;
        } 
        #endregion

        #region CRUD
        static public void Insert(VentaItemInfo oVentaItemInfo)
        {
            try
            {
                Instance().Insert(oVentaItemInfo.Nombre, oVentaItemInfo.Descripcion, oVentaItemInfo.Precio, oVentaItemInfo.VentaID, oVentaItemInfo.EventoID, oVentaItemInfo.Fotografo);
            }
            catch (Exception ex)
            {
                Hashtable addInfo = new Hashtable();
                addInfo.Add("Nombre", oVentaItemInfo.Nombre);
                addInfo.Add("Descripcion", oVentaItemInfo.Descripcion);
                addInfo.Add("Precio", oVentaItemInfo.Precio.ToString());
                addInfo.Add("VentaID", oVentaItemInfo.VentaID.ToString());
                addInfo.Add("EventoID", oVentaItemInfo.EventoID.ToString());
                addInfo.Add("Fotografo", oVentaItemInfo.Fotografo);
                
                throw ExceptionManager.Handle(ex, "Error al agregar un nuevo item de venta", addInfo);
            }
        } 
        #endregion
            
    }

}
